package org.yoome.jtools.utils;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

public class BeanUtil {

    public static void register(Class bean, BeanDefinitionRegistry registry) {
        String beanName = bean.getName();
        if (registry.containsBeanDefinition(beanName)) {
            return;
        }

        AbstractBeanDefinition beanDefinition
                = BeanDefinitionBuilder.genericBeanDefinition(bean).getBeanDefinition();
        registry.registerBeanDefinition(beanName, beanDefinition);
    }
}
